package com.lxm.controller;


import com.lxm.common.contants.LikesConstants;
import com.lxm.dto.Result;
import com.lxm.service.LikesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 点赞表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2024-10-02
 */
@RestController
@RequestMapping("/user/likes")
@Tag(name = "点赞管理")
public class LikesController {

    @Resource
    private LikesService likesService;

    @Operation(summary = "给博客、商品、评论点赞")
    @PostMapping("/{likedId}/{type}")
    public Result like(@PathVariable Long likedId, @PathVariable Integer type) {
        return likesService.checkLike(likedId, type) ? Result.fail(LikesConstants.LIKE_EXIST)
                : likesService.like(likedId, type);
    }

    @Operation(summary = "取消点赞")
    @DeleteMapping("/cancel/{likedId}/{type}")
    public Result cancelLike(@PathVariable Long likedId, @PathVariable Integer type) {
        return !likesService.checkLike(likedId, type) ? Result.fail(LikesConstants.LIKE_NOT_EXIST)
                : likesService.cancelLike(likedId, type);
    }


}

